//
//  CAPaymentView.m
//  LNH
//
//  Created by twentylx on 2018/2/18.
//  Copyright © 2018年 twentylx. All rights reserved.
//

#import "CAPaymentView.h"

@implementation CAPaymentView {
    UIView *_rootView;
}

/**
 为视图绑定 viewModel
 
 @param viewModel 要绑定的ViewModel
 @param params 额外参数
 */
- (void)bindViewModel:(id <LMViewProtocol>)viewModel withParams:(NSDictionary *)params {
    
}

/**
 初始化额外数据
 */
- (void)lm_initializeForView {
    
}

/**
 初始化视图
 */
- (void)lm_createViewForView {
    [self setNeedsUpdateConstraints];
    
    [self addSubview:self.contentView];
    [self.contentView addSubview:self.closeButton];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.lineView];
    [self.contentView addSubview:self.priceLabel];
    [self.contentView addSubview:self.payTitleLabel];
    [self.contentView addSubview:self.wechatButton];
    [self.contentView addSubview:self.alipayButton];
    [self.contentView addSubview:self.payButton];
}

- (void)updateConstraints {
    [super updateConstraints];
    
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [_closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(20);
        make.top.equalTo(self.contentView).offset(20);
        make.size.mas_equalTo(CGSizeMake(25, 25));
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.closeButton);
        make.centerX.equalTo(self.contentView);
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.contentView);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
        make.height.mas_equalTo(ONE_PIXEL);
    }];
    
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.contentView);
        make.top.equalTo(self.lineView.mas_bottom).offset(20);
    }];
    
    [_payTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(20);
        make.top.equalTo(self.priceLabel.mas_bottom).offset(40);
        make.width.mas_equalTo(120);
    }];
    
//    [_wechatButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.payTitleLabel.mas_right).offset(10);
//        make.top.equalTo(self.priceLabel.mas_bottom).offset(30);
//        make.width.mas_equalTo(150);
//    }];
    
    [_alipayButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.payTitleLabel.mas_right).offset(10);
        make.top.equalTo(self.priceLabel.mas_bottom).offset(30);
        make.width.mas_equalTo(150);
//        make.left.equalTo(self.payTitleLabel.mas_right).offset(10);
//        make.top.equalTo(self.wechatButton.mas_bottom).offset(10);
//        make.width.mas_equalTo(150);
    }];
    
    [_payButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(20);
        make.right.equalTo(self.contentView).offset(-20);
        make.bottom.equalTo(self.contentView).offset(-30);
        make.height.mas_equalTo(40);
    }];
}

#pragma mark get & set
- (UIView *)contentView {
    if (!_contentView) {
        _contentView = [UIView new];
        _contentView.backgroundColor = [UIColor whiteColor];
    }
    return _contentView;
}

- (UIButton *)closeButton {
    if (!_closeButton) {
        _closeButton = [UIButton new];
        [_closeButton setImage:LMImageNamed(@"close") forState:UIControlStateNormal];
    }
    return _closeButton;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.text = @"确认付款";
        _titleLabel.textColor = RGBCOLOR(35, 24, 21);
        _titleLabel.font = [UIFont systemFontOfSize:20];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = RGBCOLOR(217, 218, 218);
    }
    return _lineView;
}

- (UILabel *)priceLabel {
    if (!_priceLabel) {
        _priceLabel = [UILabel new];
        _priceLabel.text = @"￥：388.00";
        _priceLabel.textColor = RGBCOLOR(35, 24, 21);
        _priceLabel.font = [UIFont systemFontOfSize:24];
        _priceLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _priceLabel;
}

- (UILabel *)payTitleLabel {
    if (!_payTitleLabel) {
        _payTitleLabel = [UILabel new];
        _payTitleLabel.text = @"选择付款方式：";
        _payTitleLabel.textColor = RGBCOLOR(35, 24, 21);
        _payTitleLabel.font = [UIFont systemFontOfSize:16];
        _payTitleLabel.textAlignment = NSTextAlignmentRight;
//        _payTitleLabel.layer.borderWidth = 1;
    }
    return _payTitleLabel;
}

- (UIButton *)wechatButton {
    if (!_wechatButton) {
        _wechatButton = [UIButton new];
        [_wechatButton setImage:LMImageNamed(@"pay_wechat") forState:UIControlStateNormal];
        [_wechatButton setTitle:@"微   信" forState:UIControlStateNormal];
        _wechatButton.titleLabel.font = [UIFont systemFontOfSize:16];
        [_wechatButton setTitleColor:RGBCOLOR(35, 24, 21) forState:UIControlStateNormal];
        _wechatButton.imageEdgeInsets = UIEdgeInsetsMake(0, -60, 0,0);
        _wechatButton.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
//        _wechatButton.layer.borderWidth = 1;
        _wechatButton.hidden = YES;
    }
    return _wechatButton;
}

- (UIButton *)alipayButton {
    if (!_alipayButton) {
        _alipayButton = [UIButton new];
        [_alipayButton setImage:LMImageNamed(@"pay_alipay") forState:UIControlStateNormal];
        [_alipayButton setTitle:@"支付宝" forState:UIControlStateNormal];
        _alipayButton.titleLabel.font = [UIFont systemFontOfSize:16];
        [_alipayButton setTitleColor:RGBCOLOR(35, 24, 21) forState:UIControlStateNormal];
        _alipayButton.imageEdgeInsets = UIEdgeInsetsMake(0, -60, 0,0);
        _alipayButton.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
//        _alipayButton.layer.borderWidth = 1;
    }
    return _alipayButton;
}

- (UIButton *)payButton {
    if (!_payButton) {
        _payButton = [UIButton new];
        [_payButton setTitle:@"立即付款" forState:UIControlStateNormal];
        [_payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _payButton.titleLabel.font = [UIFont systemFontOfSize:20];
        _payButton.backgroundColor = RGBCOLOR(233, 85, 19);
    }
    return _payButton;
}

@end
